//
//  TjbShopTwo.swift
//  jhf
//
//  Created by Mac on 2021/11/05 16:53:15.
//  Copyright © 2021 jhf. All rights reserved.
//
import Foundation
import UIKit
import Moya
import CryptoSwift
import SwiftyJSON
import CooperSwift

// LogPlugin(),
// SpinnerPlugin()
// EncryptPlugin()
// RequestAlertPlugin

let TjbShopTwoProvider = MoyaProvider<TjbShopTwo>(plugins: [SpinnerPlugin(), EncryptPlugin(), LogPlugin()])

   
public enum TjbShopTwo {
     // 获取店铺banner图
     /// 1. id id integer ❤️
     case mobBannerGetbanners(Int)

     // 店铺banner图上传
     /// 1. files files array ❤️
     case mobBannerUpload(Array<Data>)

     // 店铺收藏/取消
     /// 1. id id integer ❤️
     case storeMobCollect(Int)

     // 删除
     /// 1. ids 收藏ids,英文逗号分割 string ❤️
     case storeMobDelete(String)

     // 根据字典类型获取字典数据
     /// 1. type 字典类型 string
     case mobDictGetdictbytype(String?)

     // 查看字典类型
     case mobDictGettype

     // 编辑
     case storeMobEdit

     // 附件上传
     /// 1. file file file ❤️
     /// 2. type type string ❤️
     case mobFileUpload(Data, String)

     // 获取收藏状态
     /// 1. id 店铺ID integer ❤️
     case storeMobGetcollectstatus(Int)

     // 我的店铺
     case storeMobGetmystorelist

     // 商城首页店铺信息
     /// 1. auditStatus 审核状态 1：待审核，2：审核成功，3：审核失败 integer
     /// 2. bannerStatus banner审核状态 1：待审核，2：审核成功，3：审核失败 integer
     /// 3. desc 排序的方向desc或者asc,默认为   desc string
     /// 4. inviter 邀请人 string
     /// 5. latitude 维度 number
     /// 6. longitute 经度 number
     /// 7. name 名称 string
     /// 8. orderByColumn 排序列,默认为    t.created_time  string
     /// 9. pageNum 当前记录起始索引,默认为  1 integer
     /// 10. pageSize 每页显示记录数,默认为   10 integer
     /// 11. status 店铺状态 1：开店，2：关店 integer
     /// 12. tel 电话 string
     /// 13. username 上传人账号 string
     case storeMobGetstorelist(Dictionary<String, Any>)

     // 我的店铺收藏
     case storeMobMycollect

     // 删除
     /// 1. id id integer ❤️
     case mobRemovestorebyid(Int)

     // 重新申请
     /// 1. adCode 地址 code string
     /// 2. address 地址 string
     /// 3. auditPassTime 审核通过时间 string
     /// 4. auditStatus 审核状态 1：待审核，2：审核成功，3：审核失败 integer
     /// 5. bankNo 银行卡号 string
     /// 6. bankSite 开户行地址 string
     /// 7. bannerFailReasons banner审核失败描述 string
     /// 8. bannerStatus banner审核状态 1：待审核，2：审核成功，3：审核失败 integer
     /// 9. businessTime 营业时间 09:00--18:00 string
     /// 10. businessUrl 营业执照 string
     /// 11. contacts 联系人姓名 string
     /// 12. coverUrl 店铺封面 string
     /// 13. createdTime 创建日期 string
     /// 14. createdUser 创建人 integer
     /// 15. description 描述信息 string
     /// 16. failReasons 审核失败描述 string
     /// 17. id null integer
     /// 18. inviter 邀请人 string
     /// 19. latitude 维度 number
     /// 20. longitute 经度 number
     /// 21. mainBusiness 主营产品 string
     /// 22. modifiedTime 修改日期 string
     /// 23. modifiedUser 修改人 integer
     /// 24. name 名称 string
     /// 25. payeeName 收款人姓名 string
     /// 26. sales 销量 integer
     /// 27. status 店铺状态 1：开店，2：关店 integer
     /// 28. tel 电话 string
     /// 29. type 店铺属性 1：铁甲帮认证店，2：应急认证店 string
     /// 30. userId 用户id integer
     /// 31. username 上传人账号 string
     /// 32. valid 是否可用 1:可用,0不可用 integer
     case storeMobReplaysave(Dictionary<String, Any>)

     // 入驻商城/添加店铺
     /// 1. adCode 地址 code string
     /// 2. address 地址 string
     /// 3. auditPassTime 审核通过时间 string
     /// 4. auditStatus 审核状态 1：待审核，2：审核成功，3：审核失败 integer
     /// 5. bankNo 银行卡号 string
     /// 6. bankSite 开户行地址 string
     /// 7. bannerFailReasons banner审核失败描述 string
     /// 8. bannerStatus banner审核状态 1：待审核，2：审核成功，3：审核失败 integer
     /// 9. businessTime 营业时间 09:00--18:00 string
     /// 10. businessUrl 营业执照 string
     /// 11. contacts 联系人姓名 string
     /// 12. coverUrl 店铺封面 string
     /// 13. createdTime 创建日期 string
     /// 14. createdUser 创建人 integer
     /// 15. description 描述信息 string
     /// 16. failReasons 审核失败描述 string
     /// 17. id null integer
     /// 18. inviter 邀请人 string
     /// 19. latitude 维度 number
     /// 20. longitute 经度 number
     /// 21. mainBusiness 主营产品 string
     /// 22. modifiedTime 修改日期 string
     /// 23. modifiedUser 修改人 integer
     /// 24. name 名称 string
     /// 25. payeeName 收款人姓名 string
     /// 26. sales 销量 integer
     /// 27. status 店铺状态 1：开店，2：关店 integer
     /// 28. tel 电话 string
     /// 29. type 店铺属性 1：铁甲帮认证店，2：应急认证店 string
     /// 30. userId 用户id integer
     /// 31. username 上传人账号 string
     /// 32. valid 是否可用 1:可用,0不可用 integer
     case storeMobSave(Dictionary<String, Any>)

     // 附件上传
     /// 1. file file file ❤️
     case storeMobUpload(Data)

}
    

extension TjbShopTwo: TargetType {
    
    public var method: Moya.Method {
        if ["ecommerce/store/mob/banner/getBanners", "ecommerce/store/mob/collect", "ecommerce/store/mob/getCollectStatus", "ecommerce/store/mob/getMyStoreList", "ecommerce/store/mob/myCollect", "ecommerce/store/mob/removeStoreById/"].contains(self.path) {
            return .get
        }
        return .post
    }
    
    public var sampleData: Data {
        return "{}".data(using: String.Encoding.utf8)!
    }
    
    public var task: Task {
        var params: [String:Any] = [:]
        var formData: [MultipartFormData] = []
        switch self {
            case .mobBannerGetbanners(let id):
            params["id"] = id
            break
        case .mobBannerUpload(let files):
            files.forEach { data in
                formData.append(MultipartFormData.init(provider: .data(data), name: "files", fileName: nil, mimeType: nil))
            }
            break
        case .storeMobCollect(let id):
            params["id"] = id
            break
        case .storeMobDelete(let ids):
            params["ids"] = ids
            break
        case .mobDictGetdictbytype(let type):
            params["type"] = type
            break
        case .mobDictGettype:
            break
        case .storeMobEdit:
            break
        case .mobFileUpload(let file, let type):
            params["type"] = type
            formData.append(MultipartFormData.init(provider: .data(file), name: "file", fileName: nil, mimeType: nil))
            break
        case .storeMobGetcollectstatus(let id):
            params["id"] = id
            break
        case .storeMobGetmystorelist:
            break
        case .storeMobGetstorelist(let param):
            params = params.add(param)
            break
        case .storeMobMycollect:
            break
        case .mobRemovestorebyid(let id):
            params["id"] = id
            break
        case .storeMobReplaysave(let param):
            params = params.add(param)
            break
        case .storeMobSave(let param):
            params = params.add(param)
            break
        case .storeMobUpload(let file):
            formData.append(MultipartFormData.init(provider: .data(file), name: "file", fileName: nil, mimeType: nil))
            break
        
        }
        if ["ecommerce/store/mob/file/upload", "ecommerce/store/mob/upload"].contains(self.path) {
            return .uploadCompositeMultipart(formData, urlParameters: params)
        }
        return .requestParameters(parameters: params,
                                  encoding: URLEncoding.default)
    }
    
    public var headers: [String : String]? {
        if ["ecommerce/store/mob/file/upload", "ecommerce/store/mob/upload"].contains(self.path) {
            return ["Content-type" : "multipart/form-data"]
        }
        return ["Content-type" : "application/json"]
    }
        
    public var baseURL: URL {
        return URL(string: "http://192.168.0.193:8082/tjb2/")!
    }
    
    public var path: String {
        switch self {
            
          case .mobBannerGetbanners:
            return "ecommerce/store/mob/banner/getBanners"
        
          case .mobBannerUpload:
            return "ecommerce/store/mob/banner/upload"
        
          case .storeMobCollect:
            return "ecommerce/store/mob/collect"
        
          case .storeMobDelete:
            return "ecommerce/store/mob/delete"
        
          case .mobDictGetdictbytype:
            return "ecommerce/store/mob/dict/getDictByType"
        
          case .mobDictGettype:
            return "ecommerce/store/mob/dict/getType"
        
          case .storeMobEdit:
            return "ecommerce/store/mob/edit"
        
          case .mobFileUpload:
            return "ecommerce/store/mob/file/upload"
        
          case .storeMobGetcollectstatus:
            return "ecommerce/store/mob/getCollectStatus"
        
          case .storeMobGetmystorelist:
            return "ecommerce/store/mob/getMyStoreList"
        
          case .storeMobGetstorelist:
            return "ecommerce/store/mob/getStoreList"
        
          case .storeMobMycollect:
            return "ecommerce/store/mob/myCollect"
        
          case .mobRemovestorebyid:
            return "ecommerce/store/mob/removeStoreById/"
        
          case .storeMobReplaysave:
            return "ecommerce/store/mob/replaySave"
        
          case .storeMobSave:
            return "ecommerce/store/mob/save"
        
          case .storeMobUpload:
            return "ecommerce/store/mob/upload"
        }
    }
        
}
